home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / turbocad_test1.vbs < prev    next >
Encoding:
Text File  |  2001-10-16  |  6.8 KB  |  360 lines

  1. Option Explicit
  2.  
  3. Dim tcApp
  4. Dim tcDwg
  5.  
  6. Dim TORADIANS
  7. Dim bContinue
  8.  
  9. '================== ShowDrawings ========================================
  10. Sub ShowDrawings()
  11.       Dim cnt
  12.     Dim tcDwgs
  13.     Dim tcDwg
  14.     Dim strMsg
  15.  
  16.     Set tcDwgs = tcApp.Drawings
  17.     cnt = tcDwgs.Count
  18.     MsgBox "Drawings count: " & CStr(cnt)
  19.  
  20.     If (cnt = 0) Then
  21.         bContinue = False
  22.         Exit Sub
  23.     End If
  24.  
  25.     For Each tcDwg in tcDwgs
  26.         strMsg = strMsg & tcDwg.Name
  27.         strMsg = strMsg & Chr(13) & Chr(10)
  28.     Next    
  29.     MsgBox strMsg
  30.  
  31. End Sub
  32.  
  33. '================== ShowFilters ========================================
  34. Sub ShowFilters()
  35.     Dim tcFlts
  36.     Dim tcFlt
  37.     Dim strMsg
  38.  
  39.     Set tcFlts = tcApp.Filters
  40.     MsgBox "Filters count: " & CStr(tcFlts.Count)
  41.  
  42.     For Each tcFlt in tcFlts
  43.         strMsg = strMsg & tcFlt.Name
  44.         strMsg = strMsg & Chr(13) & Chr(10)
  45.     Next    
  46.     MsgBox strMsg
  47.  
  48. End Sub
  49.  
  50. '================= ShowRegenMethods =========================================
  51.  
  52. Sub ShowRegens()
  53.     Dim tcRms
  54.     Dim tcRm
  55.     Dim strMsg
  56.  
  57.     Set tcRms = tcApp.RegenMethods
  58.     MsgBox "Regen Methods count: " & CStr(tcRms.Count)
  59.  
  60.     For Each tcRm in tcRms
  61.         strMsg = strMsg & tcRm.Name
  62.         strMsg = strMsg & Chr(13) & Chr(10)
  63.     Next    
  64.     MsgBox strMsg
  65.  
  66. End Sub
  67.  
  68. '================= ShowTieMethods =========================================
  69. Sub ShowTieMethods()
  70.  
  71.     Dim tcTms
  72.     Dim tcTm
  73.     Dim strMsg
  74.  
  75.     Set tcTms = tcApp.TieMethods
  76.     MsgBox "Tie Methods count: " & CStr(tcTms.Count)
  77.  
  78.     For Each tcTm in tcTms
  79.         strMsg = strMsg & tcTm.Name
  80.         strMsg = strMsg & Chr(13) & Chr(10)
  81.     Next    
  82.     MsgBox strMsg
  83.  
  84. End Sub
  85.  
  86. '================= ShowRenders =========================================
  87. Sub ShowRenders()
  88.     Dim tcRnds
  89.     Dim tcRnd
  90.     Dim strMsg
  91.  
  92.     Set tcRnds = tcApp.Renders
  93.     MsgBox "Renders count: " & CStr(tcRnds.Count)
  94.  
  95.     For Each tcRnd in tcRnds
  96.         strMsg = strMsg & tcRnd.Name
  97.         strMsg = strMsg & Chr(13) & Chr(10)
  98.     Next    
  99.     MsgBox strMsg
  100.  
  101. End Sub
  102.  
  103. '================ AddGraphics ==========================================
  104. Sub AddGraphics(tcGrs)
  105.  
  106. Dim tcGr1
  107. Dim tcGr2
  108.  
  109.     MsgBox "Graphics count: " & CStr(tcGrs.Count)
  110.  
  111.     Set tcGr1 = tcGrs.AddArcCenterAndPoint(0, 0, 0, 1, 1, 0, 0, 90 * TORADIANS)
  112.  
  113. '    tcGr1.MoveAbsolute 1, 1, 0
  114.  
  115.     Set tcGr2 = tcGrs.AddArcCenterAndPoint(0, 0, 0, 2, 2, 0, 0, 90 * TORADIANS)
  116.     tcGr2.Properties("PenColor") = RGB(255, 128, 64)
  117.     tcGrs.Remove tcGr2.Index
  118.     tcGrs.AddGraphic tcGr2, tcGr1.Index
  119.  
  120.     MsgBox "Graphics count: " & CStr(tcGrs.Count)
  121.  
  122. End Sub
  123.  
  124. '================ CreateBlock ==========================================
  125. Sub CreateBlock(tcGrs)
  126. Dim tcDwg
  127.  
  128.     Set tcDwg = tcGrs.Drawing
  129.     MsgBox "Blocks count: " & tcDwg.Blocks.Count
  130.  
  131.     tcGrs.CreateBlock "MyBlock"
  132.  
  133.     MsgBox "Blocks count: " & tcDwg.Blocks.Count
  134.  
  135. End Sub
  136.  
  137. '================ CreateXRefBlock ========================================
  138. Sub CreateXRefBlock(tcDwg)
  139.     Dim tcBlks
  140.  
  141.     Set tcBlks = tcDwg.Blocks
  142.     MsgBox "Blocks count: " & tcBlks.Count
  143.  
  144.     tcBlks.AddXRef "", "e:\tc70\bin\usa\drawing\drawing1.tcw"
  145.  
  146.     MsgBox "Blocks count: " & tcBlks.Count
  147.  
  148. End Sub
  149.  
  150. '================ ViewZoom ================================================
  151. Sub ViewZoom(tcVw)
  152.  
  153. Dim tcCam
  154. Dim xC
  155. Dim yC
  156. Dim w
  157. Dim h
  158. Dim ZOOM_FACTOR
  159.  
  160.     ZOOM_FACTOR = 1.2
  161.  
  162.     If (tcVw.SpaceMode = 1) Then
  163.     
  164.         Set tcCam = tcVw.Camera    
  165.         tcCam.Zoom ZOOM_FACTOR
  166.         MsgBox "Zoom"
  167.     
  168.     Else
  169.  
  170.         w = tcVw.ViewWidth
  171.         h = tcVw.ViewHeight
  172.     
  173.         xC = tcVw.ViewLeft + w / 2
  174.         yC = tcVw.ViewTop - h / 2
  175.  
  176.         w = w * ZOOM_FACTOR
  177.         h = h * ZOOM_FACTOR
  178.  
  179.         tcVw.Update = False
  180.         tcVw.ViewLeft = xC - w / 2
  181.         tcVw.ViewTop  = yC + h / 2
  182.  
  183.         tcVw.Update = True
  184.  
  185.     End If    
  186.     
  187.     MsgBox "Zoom"
  188.  
  189.     tcVw.Update = False
  190.     tcVw.Margins = True
  191.     tcVw.ZoomToExtents
  192.     MsgBox "Zoom All"
  193.  
  194. End Sub
  195.  
  196. '================ ShowAppInfo ================================================
  197. Sub ShowAppInfo()
  198. Dim cnt
  199.  
  200.     tcApp.Visible = True
  201.  
  202. '    MsgBox "Current Snap modes: " & CStr(tcApp.SnapModes)
  203.  
  204.     ShowRegens
  205. '    ShowRenders
  206. '    ShowFilters
  207. '    ShowTieMethods
  208. '    ShowDrawings
  209.  
  210.     bContinue = False
  211. End Sub
  212.  
  213. '================ EditDrawing ================================================
  214. Sub MirrorSelection (tcDwg)
  215.  
  216. Dim tcMtx
  217.  
  218. Dim tcVw
  219. Dim tcPickRes
  220.  
  221. Dim tcSelection
  222. Dim tcBBox
  223.  
  224. Dim tcGr
  225. Dim tcGrM
  226. Dim tcVrt0
  227. Dim tcVrt1
  228.  
  229. Dim xC
  230. Dim yC
  231. Dim zC
  232. Dim angle
  233. Dim dx
  234. Dim dy
  235. Dim dz
  236.  
  237.     
  238.     Set tcSelection = tcDwg.Selection
  239.     if (tcSelection.Count = 0) then exit sub
  240.  
  241.     MsgBox "Click mirror line"
  242.     Set tcVw = tcDwg.ActiveView
  243.     tcVw.GetMouseClick xC, yC
  244.  
  245.     Set tcPickRes = tcVw.PickPoint(xC, yC)
  246.     if (tcPickRes.Count = 0) then exit sub
  247.  
  248.     Set tcVrt0 = tcPickRes(0).ClosestVertex
  249.     tcVw.WorldToView tcVrt0.X, tcVrt.Y, tcVrt.Z, xC, yC, zC
  250.  
  251.     Set tcGr = tcPickRes(0)
  252.     tcGr.GetDistance xC, yC, zC, , tcGrM
  253.     
  254.     Set tcVrt0 = tcGrm.Vertices(0)
  255.     Set tcVrt1 = tcGrM.Vertices(1)
  256.  
  257.     dx = tcVrt1.X - tcVrt0.X
  258.     dy = tcVrt1.Y - tcVrt0.Y
  259.     if dx = 0 then
  260.         angle = - 90 * TORADIANS
  261.     else
  262.         angle = -Atn(dy / dx)
  263.     end if
  264.  
  265. '    Set tcBBox = tcSelection.CalcBoundingBox
  266. '    xC = (tcBBox.Min.X + tcBBox.Max.X) / 2
  267. '    yC = (tcBBox.Min.Y + tcBBox.Max.Y ) / 2
  268. '    yC = (tcBBox.Min.Z + tcBBox.Max.Z ) / 2
  269.  
  270.     Set tcMtx = CreateObject("TurboCAD.Matrix")
  271. '    tcMtx.TranslateScaleAndRotateZ 8, 8, 0,  1, 1, 1, 360 * TORADIANS
  272. '    tcMtx.Translate 8, 8, 0
  273.  
  274.  
  275. '    for each tcGr in tcSelection
  276. '        tcGr.MoveRelative 8, 8, 0
  277. '        tcGr.Update
  278. '        tcGr.Select
  279. '    next
  280.  
  281.     for each tcGr in tcSelection
  282.         tcGr.RotateAxis angle, 0, 0, 1, tcVrt0.X, tcVrt0.Y, tcVrt0.Z
  283.         tcGr.Update
  284.         tcGr.Select
  285.     next
  286.  
  287. '    for each tcGr in tcSelection
  288. '        tcGr.RotateAxis -90 * TORADIANS, 0, 0, 1
  289. '        tcGr.Update
  290. '        tcGr.Select
  291. '    next
  292.  
  293.     Set tcBBox = tcSelection.CalcBoundingBox
  294.     xC = (tcBBox.Min.X + tcBBox.Max.X) / 2
  295.     yC = (tcBBox.Min.Y + tcBBox.Max.Y ) / 2
  296.     yC = (tcBBox.Min.Z + tcBBox.Max.Z ) / 2
  297.  
  298.     tcMtx.Identity
  299.     tcMtx.TranslateScaleAndRotateZ 0, 0, 0, -1, 1, 1, 360 * TORADIANS, xC, yC, zC
  300.  
  301.     for each tcGr in tcSelection
  302.         tcGr.Transform tcMtx
  303.         tcGr.Update
  304.         tcGr.Select
  305.     next
  306. end sub
  307.  
  308. '================ EditDrawing ================================================
  309. Sub EditDrawing(tcDwg)
  310. Dim tcGrs
  311.  
  312.     Set tcGrs = tcDwg.Graphics
  313.  
  314.     AddGraphics tcGrs
  315. '    CreateBlock tcGrs
  316. '    CreateXRefBlock tcDwg
  317. '    MirrorSelection tcDwg
  318.  
  319.     ViewZoom tcDwg.ActiveView
  320. End Sub
  321.  
  322. '================ CloseDrawing ================================================
  323. Sub CloseDrawing(tcDwg)
  324.  
  325.     tcDwg.Close False
  326.  
  327. End Sub
  328.  
  329.  
  330. '================ Main =================================================
  331. Sub Main ()
  332.  
  333.     Set tcApp = CreateObject("TurboCAD.Application")
  334. '    Set tcDwg = CreateObject("TurboCAD.Drawing")
  335. '    Set tcApp = tcDwg.Application
  336.     tcApp.Visible = false
  337.     tcApp.Visible = true
  338.  
  339.     ShowAppInfo
  340.  
  341.     If (bContinue = False) Then
  342.         Exit Sub
  343.     End If
  344.  
  345. '    EditDrawing tcDwg
  346. '    CloseDrawing tcDwg
  347.  
  348. '    ShowDrawings
  349.  
  350. End Sub
  351.  
  352.     TORADIANS = 3.14159265358979 / 180
  353.     bContinue = True
  354.  
  355.     Main
  356.  
  357. '    tcApp.Quit
  358.  
  359.     MsgBox "Done"
  360.